`timescale 1ns / 1ps
(*DONT_TOUCH = "TRUE"*)
module bcc_top(
    input sys_clk,
    input rst_n,

    input	[15:0]			Din	        ,
	input					busy		,
	input					Fdata		,

	output					Cs			,
	output					Rd			,
	output					cvtA		,
	output					cvtB		,
	output					phy_rst     ,

    //uart
    input               uart_rxd        ,    //串口接收的数据
    output              uart_txd        ,    //串口发送的数据

    //cmd
    output              device_0,
    output              device_1,

    //led
    output [5:0] seg_sel , //数码管位选信号
    output [7:0] seg_led //数码管段选信号
    );

    wire signed [15:0] ch1;
    wire clk_50m;

    ad_top u_ad_top(
        .sys_clk(sys_clk),
        .rst_n(rst_n),
        .Din(Din),
        .busy(busy),
        .Fdata	(Fdata)	,
        .Cs	(Cs)		,
        .Rd	(Rd)		,
        .cvtA(cvtA),
        .cvtB(cvtB),
        .phy_rst(phy_rst),
        .clk_50m(clk_50m),
        .ch1(ch1)
    );

    wire [31:0] count;
    wire clear_signal;
    ParticleCounter u_ParticleCounter(
        .clk(clk_50m),
        .rst_n(rst_n),
        .start(1'b1), //开始计数信号
        .clear(clear_signal), //清空计数信号脉冲
        .adc_data(ch1),
        .count(count)
    );

    wire [15:0] fun_parmeter;
    wire fun0_en;
    wire fun1_en;
    wire fun2_en;
    wire fun3_en;
    wire fun4_en;
    top_uart_packet u_top_uart_packet(
        .sys_clk(clk_50m),
        .sys_rst_n(rst_n),

        .count(count[15:0]),

        .uart_rxd(uart_rxd),
        .uart_txd(uart_txd),

        .fun0_en(fun0_en),
        .fun1_en(fun1_en),
        .fun2_en(fun2_en),
        .fun3_en(fun3_en),
        .fun4_en(fun4_en),
        .fun_parmeter(fun_parmeter)
    );

    wire divice_1_en;
    wire pid_en;
    wire device_0_en;
    wire count_stop_pluse;
    //bcc控制模块
    bcc_cmd u_bcc_cmd(
        .clk                 (clk_50m),
        .rst_n               (rst_n),

        .fun0_en             (fun0_en),
        .fun1_en             (fun1_en),
        .fun2_en             (fun2_en),
        .fun3_en             (fun3_en),
        .fun4_en             (fun4_en),
        .stop_pluse          (count_stop_pluse),

        .count(count), //[31:0]
        .cmd_parameter(fun_parmeter), //[15:0]

        .device_0(device_0_en), //电机使能 0/1
        .device_1(divice_1_en), //电磁阀
        .clear_signal(clear_signal), //清空信号
        .pid_en(pid_en)
    );

    //pid控制pwm占空比
    pid_cmd u_pid_cmd(
        .clk                 (clk_50m       ),
        .rst_n               (rst_n     ),

        .pid_en(pid_en),
        .device_0_en(device_0_en),
        .count(count),//[31:0]
        .target_count(fun_parmeter),//[31:0]

        .device_0_pwm(device_0),
        .stop_pluse(count_stop_pluse) //暂时不连接
    );


    //电池阀翻转信号
    pulse_generator u_pulse_generator(
        .clk(clk_50m),                       // 系统时钟
        .rst_n(rst_n),                       // 同步复位信号
        .input_signal(divice_1_en),    // 控制输入
        .output_signal(device_1)             // 模块输出
    );

    seg_led_top u_seg_led_top(
    .clk(clk_50m) , //时钟信号
    .rst_n(rst_n), //复位信号（低有效）

    .data(count[19:0]), //数值
    .point(6'b0), //数码管小数点的位置,这儿全是0
    .en(1'b1), //数码管使能信号
    .sign(1'b0) , //符号位,高电平显示负号(-)

    .seg_sel(seg_sel) , //数码管位选信号
    .seg_led(seg_led) //数码管段选信号
    );

    ila_0 u_ila_0 (
	.clk(sys_clk), // input wire clk
	.probe0(device_0),
    .probe1(device_1),
    .probe2(ch1)//[15:0]
    );
endmodule
